package HelloAlgo.sort;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int[] nums = {5,2,5,1,4,6,1,4,7,3};
        BubbleSort bubbleSort = new BubbleSort();
        bubbleSort.bubble(nums);
        Arrays.stream(nums).forEach(num -> System.out.println(num));
    }
    void bubble(int[] nums){
        Boolean flag = false;
        for(int i = nums.length-1;i>0;i--){
            for(int j = 0;j<i;j++){
                if(nums[j]>nums[j+1]){
                    int temp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = temp;
                    flag = true;
                }
            }
            if(!flag){
                break;
            }
        }
    }
}
